//点击返回顶部
let scrolltop = document.documentElement.scrollTop
$("#foot ul .li3").click(function () {
    $("html,body").animate({ scrollTop: 0 }, 500)
})
//点击图标返回首页
$("#header img").click(function(){
    window.location.href="../index.html"
})
//处理url
let reg = /([^&=]+)=?([^&]*)/g
let str = window.location.href
var brandTitleId = reg.exec(str)[2]
var brandName = decodeURI(reg.exec(str)[2])
console.log(brandTitleId);
console.log(brandName);
//请求数据渲染标题分类
let strtitle=`
<a href="" class="puba a1">首页</a> &gt; 
<a href="" class="puba a2">全部分类</a> &gt; 
<a href="" class="puba a3">${brandName}</a>
<p class="screen">筛选</p>
`
$(".tag").html(strtitle)
//点击上一级class类返回
$("#tag .tag .a2").attr("href","../pages/ppdq.html")
$("#tag .tag .a1").attr("href","../index.html")
//请求分类数据渲染页面结构
fetch(`http://chst.vip:1234/api/getbrandproductlist?brandtitleid=${brandTitleId}`)
.then(body=>body.json())
.then(res=>{
   let arr = res.result
   console.log(arr);
   let str = ""
   arr.forEach(item => {
       str+=`
    <li cname=${brandName} brandTitleId=${brandTitleId} clickid=${item.productId}>
       ${item.productImg}
       <p class="jieshao">${item.productName}</p>
       <p class="jiage">${item.productPrice}</p>
       <p class="pl">${item.productQuote}&emsp;<span class="iconfont icon-pinglun"></span>${item.productCom}</p>
    </li>            
       `
   });
   $("#main .lis").html(str)
   //点击携带参数跳转
   $("#main .lis").on("click","li img",function(e){
    console.log(1);
    let _this = e.target
    let clickid = $(_this).parent().attr("clickid")
    let cname = $(_this).parent().attr("cname")
    // let thisname = $(_this).parent().attr("thisname")
    //跳转页面，动态拼接id
    window.location.href=`ppdq_class_detail.html?productId=${clickid}&cname=${cname}&brandTitleId=${brandTitleId}`
   })
})